<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Blogger extends Admin_Controller {

    public function blogger_list(){

        $this->load->view('blogger_add');
    }

    public function aa(){
    	$this->load->library('eccang');
    	$page = $this->input->post('page');
    	$res = $this->eccang->aa($page);
    	foreach ($res['data'] as $k => $v) {
    		$sku[] = $v['productSku'];
    	}
    	$this->db->where_in('sku_sn',$sku)->update('goods_sku',['is_on_sale'=>0]);
    }

    public function goods_sku(){
    	$arr = $this->db->from('goods_sku')->select('goods_id')->group_by('goods_id')->limit(5,0)->where('is_on_sale', 0)->get()->result_array();
    	foreach ($arr as $k => $v) {
    		$goods_id .=$goods_id.','.$v['goods_id'];
    	}
    	$goods_id = substr($goods_id,1);
    	$sql='SELECT count(*) count,goods_id FROM pcs_goods_sku WHERE goods_id in ('.$goods_id.') GROUP BY(goods_id)';
    	$query = $this->db->query($sql)->result_array();
    	print_r($query);die;
    	foreach ($query as $key => $value) {
    		$aaaa = $this->db->from('goods_sku')->select('count(*) counts')->where(['goods_id'=>$value['goods_id'],'is_on_sale'=>0])->get()->row_array();
    		if($value['count'] == $aaaa['counts']){





    			echo 1;die;
    		



    		}
    	}
    }





    public function e_sku_select(){
        $this->load->library('eccang');
        $page = $this->db->from('page')->select('page')->where(['status'=>0])->get()->row_array();
        if(empty($page)){
            return false;
        }
        $data['pageSize'] = 100;
        $data['page'] = $page['page'];
        $res = $this->eccang->same_list_sku($data);
        if(!empty($res['data'])){
            foreach ($res['data'] as $k => $v) {
                $v['track']             = json_encode($v['track']);
                $v['single_net_number'] = json_encode($v['single_net_number']);
                $v['detail']            = json_encode($v['detail']);
                $this->db->insert('purchase_order_e',$v);
                $id = $this->db->insert_id();
                foreach (json_decode($v['detail'],true) as $key => $val) {
                    $val['po_id'] = $id;
                    $this->db->insert('purchase_goods_e',$val);
                }
            }
        }
        
        $this->db->where(['page'=>$page['page']]);
        $this->db->set('status',1);
        $this->db->update('page');
    }

    // public function xinpic(){
    //     header('Content-Type: image/png');//输出协议头

    //     $dst_path = 'http://sumerbikini.com/album/2019/12/31/4930e7941b46ecb552680e543beff137.png';//背景图
    //     $src_path = 'http://qr.liantu.com/api.php?m=0&w=200&text=https://www.aeink.com';//这是我用的是二维码
    //     //创建图片的实例
    //     $dst = imagecreatefromstring(file_get_contents($dst_path));//读取背景图片数据流
    //     $src = imagecreatefromstring(file_get_contents($src_path));//读取二维码数据流
    //     //获取水印图片的宽高
    //     list($src_w, $src_h) = getimagesize($src_path);
    //     //将水印图片复制到目标图片上，最后个参数100是设置透明度，这里实现不透明效果
    //     imagecopymerge($dst, $src, 1360, 833, 0, 0, $src_w, $src_h, 100);
    //     //如果水印图片本身带透明色，则使用imagecopy方法
    //     //imagecopy($dst, $src, 10, 10, 0, 0, $src_w, $src_h);
    //     //设置水印文字颜色
    //     //SIMYOU.TTF 是幼圆字体
    //     $col = imagecolorallocatealpha($dst,0,0,0,0);
    //     //添加水印文字
    //     //30 是字体大小
    //     //215横坐标
    //     //875 980 是纵坐标
    //     imagettftext($dst,30,0,215,875,$col,"SIMYOU.TTF",'AEINK');
    //     imagettftext($dst,30,0,215,980,$col,"SIMYOU.TTF",'www.aeink.com');
    //     //输出图片
    //     list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
    //     imagepng($dst);
    // }

//     public function xinpic(){
//         header ('Content-Type: image/png');
//         // $im = @imagecreatetruecolor(220, 120) or die('Cannot Initialize new GD image stream');
//         // $text_color = imagecolorallocate($im, 233, 14, 91);
//         // imagestring($im, 1, 60, 60,  'A Simple Text String', $text_color);
//         // imagepng($im);
//         //imagedestroy($im);
//         $im = imagecreatetruecolor(900, 250);//创建一张宽1920*1080的图片

//         $white = imagecolorallocate($im, 255, 255, 255);//设置一个颜色为白色的函数，三个数字分别对应RGB
// // $path_2 = 'http://sumerbikini.com/album/2019/12/31/938b6ef7dba1dbe682e47bbc42682f30.png';
//         imagefill($im, 0, 0, $white);//使用刚才的白色函数来填充创建的空白图片，0 0代表从图片的起点

//         $head_img = 'http://sumerbikini.com/album/2019/12/31/4930e7941b46ecb552680e543beff137.png';//这里定义一张图片，可以是路径也可以是url

//         // $img = getimagesize($head_img);
//         // print_R($img);die;

//         $src_img = imagecreatefrompng($head_img);
//         //通过php的函数imagesx()获得图像资源的宽度、imagesy()获得图像资源的高度
//         $src_w = imagesx($src_img);
//         $src_h = imagesy($src_img);
//         imagecopyresized($im, $src_img, 0, 0, 0, 0, 212, 281, 900, 1125);
//         // imagecopyresized($im, $src_img, 213, 0, 0, 0, 212, 281, 900, 1125);
//         //($im, $src_img, 0,0, 0,0, $src_w, $src_h);
//         // imagecopy($im, $src_img, 200,0, 0,0, $src_w, $src_h);

//         // imagecopy($im, $head_img, 50, 50, 50, 50, 1920, 1920);//复制定义的图片到白色图片上，前两个0分别是复制图片的X轴，Y轴，起点是左上角。后两个0是放置位置的X轴和Y轴，最后1920*680是复制图片的大小

//         // imagettftext($im, 1, 0, 0, 1160, $white, 0, '文字描述');//第一个数字是文字大小，第二个是旋转角度，第三个为宽度起点，0表示左边0像素位置开始，第四个数字为高度起点，代表从上往下1160像素开始，$white这个代表刚才设置白色，$font代表字体，可以定义为字体路径，最后的就是要放上去的文字了。
//         imagepng($im);
//     }
    //文字
    public function xinpic(){
        header ("Content-type: image/png");
 
        // $str = "aaa";
        // $im = imagecreate(100,120);
        // $white = imagecolorallocate($im,0xFF,0xFF,0xFF);
        // imagecolortransparent($im,$white);  //imagecolortransparent() 设置具体某种颜色为透明色，若注释
        // $black = imagecolorallocate($im,0x00,0x00,0x00);
         
        // imagettftext($im,15,0,50,40,$black,"simkai.ttf",$str); //字体设置部分linux和windows的路径可能不同
        // header("Content-type:image/png");
        // imagepng($im);//文字生成的图片
         
        //两张图片合成方法
        $A = "http://sumerbikini.com/album/2019/12/31/4930e7941b46ecb552680e543beff137.png";
        $B = "http://sumerbikini.com/album/2019/12/31/938b6ef7dba1dbe682e47bbc42682f30.png";
 
        $x = 10;
        $y = 20;
        $rh = 100;
         
        $im1 = imagecreatefromstring(file_get_contents($A));
        $im2 = imagecreatefromstring(file_get_contents($B));
         
        imagecopymerge($im1, $im2, $x, $y, 0, 0, 500, 500, $rh);
        imagecopymerge($im1, $im2, 300, $y, 0, 0, 500, 800, $rh);
        
        imagepng($im1,'files/1.png'); 
    }
    
    /**
     * desription 压缩图片
     * @param sting $imgsrc 图片路径
     * @param string $imgdst 压缩后保存路径
     */
    public function compressedImage() {
        $imgsrc = 'http://sumerbikini.com/album/2019/12/31/4930e7941b46ecb552680e543beff137.png';
        $imgdst = '/files/model_24/after/';
        list($width, $height, $type) = getimagesize($imgsrc);
       
        $new_width = $width;//压缩后的图片宽
        $new_height = $height;//压缩后的图片高
 
        if($width >= 200){
            $per = 200 / $width;//计算比例
            $new_width = $width * $per;
            $new_height = $height * $per;
        }
 
        switch ($type) {
            case 1:
                $giftype = check_gifcartoon($imgsrc);
                if ($giftype) {
                    header('Content-Type:image/gif');
                    $image_wp = imagecreatetruecolor($new_width, $new_height);
                    $image = imagecreatefromgif($imgsrc);
                    imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                    //90代表的是质量、压缩图片容量大小
                    imagejpeg($image_wp, $imgdst, 90);
                    imagedestroy($image_wp);
                    imagedestroy($image);
                }
                break;
            case 2:
                header('Content-Type:image/jpeg');
                $image_wp = imagecreatetruecolor($new_width, $new_height);
                $image = imagecreatefromjpeg($imgsrc);
                imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                //90代表的是质量、压缩图片容量大小
                imagejpeg($image_wp, $imgdst, 90);
                imagedestroy($image_wp);
                imagedestroy($image);
                break;
            case 3:
                header('Content-Type:image/png');
                $image_wp = imagecreatetruecolor($new_width, $new_height);
                $image = imagecreatefrompng($imgsrc);
                imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                //90代表的是质量、压缩图片容量大小
                imagepng($image_wp);
                // imagepng($image_wp, $imgdst, 90);
                imagedestroy($image_wp);
                imagedestroy($image);

                break;
        }
    }
}
